/*
 * @Author: xuxueliang
 * @Date: 2022-03-05 13:23:14
 * @LastEditTime: 2022-04-03 18:25:44
 * @LastEditors: xuxueliang
 * @Description:
 */
// import LocomotiveScroll from 'locomotive-scroll';
function initRotate(e) {
  console.log('initRotate', arguments);
}
$(function () {
  if (!window.LocomotiveScroll) {
    return false;
  }
  window.$scroll = new LocomotiveScroll({
    el: document.querySelector('[data-scroll-container]'),
    smooth: true,
    // multiplier: 10,
    // smoothMobile: true,
    smartphone: {
      smooth: true,
    },
  });
  // setTimeout(() => {
  //   alert($('.one-slide>.imgs').height());
  // });
  $scroll.on('call', function (arg, event, elm) {
    let [eventName, flag] = arg;
    if (eventName == 'count') {
      $('#' + flag).countTo();
    } else if (arg == 'initRotate') {
      initRotate(elm);
    }
    // console.log('call', this, arg);
  });

  function initRotate(currentElements) {
    const target = $(currentElements.el);
    const progress = currentElements.progress;
    if (target.attr('data-index') == undefined) return;
    const left = target.attr('data-index') % 2 == 0;
    const el = target.find('.sure-item')[0];
    if (left) {
      el.style.transform = `rotate(${-0 - progress * 15}deg)`;
    } else {
      el.style.transform = `rotate(${0 + progress * 15}deg)`;
    }
  }
  $scroll.on('scroll', (args) => {
    // if (args.currentElements['byzx']) {
    Object.keys(args.currentElements).forEach((v) => {
      // console.log(v, args.currentElements[v].progress);
      initRotate(args.currentElements[v]);
    });
    // }
    // Get all current elements : args.currentElements
    // if (typeof args.currentElements['hey'] === 'object') {
    //   let progress = args.currentElements['hey'].progress;
    //   console.log(progress);
    //   // ouput log example: 0.34
    //   // gsap example : myGsapAnimation.progress(progress);
    // }
  });
});
